package com.transaction.manage.service;

import com.transaction.manage.localMapper.SequenceMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 定时任务
 */
@Component
public class ScheduledService {

    private static Logger LOGGER = LoggerFactory.getLogger(ScheduledService.class);

    @Autowired
    private SequenceMapper sequenceMapper;

    @Autowired
    private TaService taService;

    //    @Scheduled(cron = "0 */1 * * * ?")//每分钟执行

    /**
     * 重置序列的初始值
     */
//    @Scheduled(cron = "0 0 1 * * ?") //每天1点执行
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void resetSequenceValue(){
        sequenceMapper.resetValue("outContractNo");
        LOGGER.info("重置外部合同号序列");
        sequenceMapper.resetValue("requestNo");
        LOGGER.info("重置Ta申请单编号序列");
        sequenceMapper.resetValue("taSerialNo");
        LOGGER.info("重置申请单序列号序列");
    }

    /**
     * 模拟生成TA产品的万份收益和净值
     */
    @Scheduled(cron = "0 0 1 * * ?") //每天1点执行
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void createTaFundNetValueAndIncome(){
        LOGGER.info("定时生成TA产品的净值或者万份收益和七日年化");
        taService.createTaFundNetValueAndIncome();
    }

}
